/*
package com.itheima.reggie.common;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import java.util.concurrent.TimeUnit;

@Aspect
@Component
public class CacheAspect {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Around("@annotation(com.itheima.reggie.annotation.FrontCache)")
    public R around(ProceedingJoinPoint pjp) throws Throwable {

        String key = "dish_"+args[0].getCategoryId()+"_"+1;
        Object result = redisTemplate.opsForValue().get(key);
        if (result != null){
            return R.success(result);
        }
        R proceed = (R) pjp.proceed();

//        存入redis中
       redisTemplate.opsForValue().set(key,result,24, TimeUnit.HOURS);

        return proceed;

    }
}
*/
